<?php
/**
 * Created by PhpStorm.
 * User: liuguang
 * Date: 2018/11/7
 * Time: 16:20
 * desc:订单
 */
namespace app\index\controller;

use think\Controller;
use app\index\model\Indent;
class Indents extends Comm
{
    //代付款订单首页
    public function payindents()
    {
        $ind=new Indent();
        $rs=$ind->index(5,6);
        $this->assign('rs',$rs);
        $this->assign('i',1);
        return view('index');
    }
    //代发货订单首页
    public function sendindents()
    {
        $ind=new Indent();
        $rs=$ind->index(3,6);
        $this->assign('rs',$rs);
        $this->assign('i',1);
        return view('index');
    }
    //待收货订单首页
    public function getindents()
    {
        $ind=new Indent();
        $rs=$ind->index(2,6);
        $this->assign('rs',$rs);
        return view('index');
    }
    //待退款订单首页
    public function backindents()
    {
        $ind=new Indent();
        $rs=$ind->index(0,1);
        $this->assign('rs',$rs);
        return view('index');
    }
    //已完成订单首页
	public function finishindents()
    {
		$ind=new Indent();
		$rs=$ind->index(4,6);
		$this->assign('rs',$rs);
        $this->assign('i',1);
        return view('index');
    }
	//订单未处理数量
	public function indentnum()
	{
		$num=Indent::where('window',0)->count();
		echo $num;
	}
	//订单修改
	public function modindents()
    {
		$ind=new Indent;
		if(isset($_POST['sub']))
		{
					$rs=$ind->modindent();
            zsgc('添加了订单数据');
				if($rs)
				{
                    switch ($_POST['tid']){
                        case 0:$this->success('操作成功','index/indents/backindents');break;
                        case 1:$this->success('操作成功','index/indents/backindents');break;
                        case 2:$this->success('操作成功','index/indents/getindents');break;
                        case 3:$this->success('操作成功','index/indents/sendindents');break;
                        case 4:$this->success('操作成功','index/indents/finishindents');break;
                        case 5:$this->success('操作成功','index/indents/payindents');break;
                    }
				}
				else
				{
				    switch ($_POST['tid']){
				        case 0:$this->error('操作失败','index/indents/backindents');break;
                        case 1:$this->error('操作失败','index/indents/backindents');break;
                        case 2:$this->error('操作失败','index/indents/getindents');break;
                        case 3:$this->error('操作失败','index/indents/sendindents');break;
                        case 4:$this->error('操作失败','index/indents/finishindents');break;
                        case 5:$this->error('操作失败','index/indents/payindents');break;
                    }
				}
		}
		else{
			$rs=$ind->alias('ind')
			->join('issue','ind.issueid=issue.id','left')
			->join('user','ind.userid=user.id','left')
			->join('agency','ind.agencyid=agency.id','left')
			->field('ind.*,issue.name,user.name,agency.name,issue.name as iname,user.name as uname')
			->where('ind.id',input('hid'))
			->find()
            ->getData();
			$this->assign('rs',$rs);
			zsgc('修改了订单数据');
			return view('modindents');
		}

    }
	//退款管理
	public function modindents1()
	{
		$ind = new Indent;
		$hid=input('id');
		$rs = $ind-> modindent1($hid);

		if($rs==false)
		{
			show(0,'退款失败');
		}else
		{
			show(1,'退款成功');
		}
	}
	//是否处理订单
    public function modindents2()
    {  $ind = new Indent;
        if(isset($_POST['sub']))
        {

            $hid=input('hid');
            $rse = $ind-> modindent2($hid);
            if($rse)
            {
                $this->success('操作成功','index/indents/index');
            }
            else
            {
                $this->error('操作失败','index/indents/index');
            }
        }
        else {
            $rs = $ind->alias('ind')
                ->join('issue', 'ind.issueid=issue.id', 'left')
                ->join('user', 'ind.userid=user.id', 'left')
                ->join('agency', 'ind.agencyid=agency.id', 'left')
                ->field('ind.*,issue.name,user.name,agency.name,issue.name as iname,user.name as uname')
                ->where('ind.id', input('hid'))
                ->find();
            $this->assign('rs', $rs);
            return view('modIndents1');
        }
    }
	//订单删除
	public function delindent()
    {
        zsgc('删除了订单数据');
        return view('delindent');
    }
    public function xiangqing()
    {
        $ind = new Indent;
        $rs = $ind->alias('ind')
            ->join('issue', 'ind.issueid=issue.id', 'left')
            ->join('user', 'ind.userid=user.id', 'left')
            ->join('agency', 'ind.agencyid=agency.id', 'left')
            ->join('reason','ind.dnumber=reason.id','left')
            ->field('ind.*,issue.name,user.name,agency.name,issue.name as iname,user.name as uname,reason.photo as rphoto,reason.reason')
            ->where('ind.id', input('hid'))
            ->find();
        $this->assign('rs', $rs);

        return view('xiangqing');
    }
}
